package com.cykj.service.Impl;

import com.cykj.dto.ResponseDto;
import com.cykj.mapper.AppointmentRecordMapper;
import com.cykj.service.AppointmentRecordService;
import com.cykj.vo.AddAppoimentVo;
import com.cykj.vo.BookingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @BelongsProject: Psychology
 * @BelongsPackage: com.cykj.service.Impl
 * @Author: 小林
 * @CreateTime: 2025-02-12 14:29
 * @Description: 预约记录表service层
 * @Version: 1.0
 */
@Service
public class AppointmentRecordServiceImpl implements AppointmentRecordService {
    @Autowired
    private AppointmentRecordMapper appointmentRecordMapper;

    /**
     * 插入预约记录
     * @param vo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseDto insertAppoiment(AddAppoimentVo vo) {
        int i1 = appointmentRecordMapper.updateisFreeTime(vo);
        if (i1 > 0) {
            int i = appointmentRecordMapper.insertAppoiment(vo);
            if (i > 0) {
                return new ResponseDto(1, "预约成功", i);
            }
            return new ResponseDto(0, "预约失败", i);
        } else {
            return new ResponseDto(0, "预约失败", i1);
        }
    }

    /**
     * 修改内容
     * @param vo
     * @return
     */
    @Override
    public ResponseDto updateContent(BookingVo vo) {
        int i = appointmentRecordMapper.updateContent(vo);
        if (i > 0) {
             return ResponseDto.success("修改成功！");
        }
        return ResponseDto.error("修改失败");
    }
}

